package com.badibadi.activity;

import com.badibadi.fragment.AfterLandingMessageItem00;
import com.badibadi.fragment.AfterLandingMessageItem01;
import com.badibadi.fragment.AfterLandingMessageItem02;
import com.badibadi.fragment.AfterLandingMessageItem03;
import com.badibadi.fragment.AfterLandingMessageItem04;
import com.badibadi.fragment.AfterLandingMessageItem05;
import com.badibadi.fragment.AfterLandingMessageItem06;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.anim;
import com.badibadi.uniclubber.R.drawable;
import com.badibadi.uniclubber.R.id;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;
import com.badibadi.uniclubber.R.string;
import com.libjph.util.StringUtil;
import com.view.my_view.PaoPao_Button;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ActionBar.Tab;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
//消息通知  7ge after_landing_title2
public class NoticeActivity extends Activity {

	private String uid="1";
	private ActionBar actionBar;
	String messageNum;//需要传入消息数量
	NotificationManager nm;
	static final int NOTIFICATION_ID = 0x123;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_notice);
     
		
		uid=Utils.getUid(NoticeActivity.this);
		messageNum=getIntent().getStringExtra("messageNum");
		nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		initActionBar();
	}

	private void initActionBar() {
		// TODO Auto-generated method stub
		   actionBar=getActionBar();
			
			//设置ActionBar的背景
			actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.blue_bg));
			//设置导航模式(只有一个呗选中)
			actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
			//actionBar.setDisplayShowTitleEnabled(false);
			actionBar.setDisplayShowTitleEnabled(true);//设置是否显示标签
			actionBar.setDisplayHomeAsUpEnabled(true);
			actionBar.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.white_bg));
			actionBar.setTitle(getResources().getString(R.string.l_xb107));
			
			//actionBar.setDisplayUseLogoEnabled(true);
			//actionBar.setHomeButtonEnabled(true);//将应用程序的标题设为可点击
			actionBar.setDisplayHomeAsUpEnabled(true);//将应用程序标题设为可点击，并且加上左键头
			//actionBar.setSelectedNavigationItem(0);//下拉列表导航
			
			LayoutInflater inflater=LayoutInflater.from(NoticeActivity.this);
			View v=inflater.inflate(R.layout.notice_title, null);
			LinearLayout paopao=(LinearLayout)v.findViewById(R.id.paoPaoButton1);
			paopao.setBackgroundResource(R.drawable.after_landing_title2);
			TextView message=(TextView)v.findViewById(R.id.messageNum);
			if(!StringUtil.isNullOrEmpty(messageNum))
			{
//				Intent intent = new Intent(NoticeActivity.this,
//						ClubListActivity.class);
//				PendingIntent pi = PendingIntent.getActivity(NoticeActivity.this,
//						0, intent, 0);
//				Notification notify = new Notification.Builder(this)
//				// 设置打开该通知，该通知自动消失
//						.setAutoCancel(true)
//						// 设置显示在状态栏的通知提示信息
//						.setTicker("有新消息")
//						// 设置通知的图标
//						.setSmallIcon(R.drawable.ic_launcher)
//						// 设置通知内容的标题
//						.setContentTitle("一条新通知")
//						// 设置通知内容
//						.setContentText("恭喜你")
//						 .setDefaults(Notification.DEFAULT_SOUND
//						 |Notification.DEFAULT_LIGHTS)
//						.setWhen(System.currentTimeMillis())
//						// 设改通知将要启动程序的Intent
//						.setContentIntent(pi).build();
//				// 发送通知
//				nm.notify(NOTIFICATION_ID, notify);
				if(Integer.parseInt(messageNum)>99)
				{
					message.setText("99+");
				}
				else
				{
					message.setText(messageNum);
				}
			}
			if(messageNum.equals("0"))
			{
				v.findViewById(R.id.f_messageNum).setVisibility(View.INVISIBLE);
			}
			
			
			Bitmap d=ImageTools.loadBitmapFromView(this, v,DisplayUtil.dip2px(this, 70),DisplayUtil.dip2px(this, 70));
			Drawable dd=ImageTools.bitmapToDrawable(d);
			
			actionBar.setIcon(dd);//设置应用标题的背景图     R.drawable.after_landing_title2
			//第一个选项卡
			ActionBar.Tab tab=actionBar.newTab();
			ActionBar.Tab tab2=actionBar.newTab();
			ActionBar.Tab tab3=actionBar.newTab();
			actionBar.addTab(actionBar.newTab()
					.setText(getResources().getString(R.string.Pair))
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTag(0)
					.setTabListener(new MyTabListener()));
			actionBar.addTab(actionBar.newTab()
					.setText(getResources().getString(R.string.SetUp))
					.setTag(1)
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTabListener(new MyTabListener()));
			actionBar.addTab(tab3.setText(getResources().getString(R.string.Praise))
					.setTag(2)
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTabListener(new MyTabListener()));
			actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.Comment))
					.setTag(3)
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTabListener(new MyTabListener()));
			actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.Share))
					.setTag(4)
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTabListener(new MyTabListener()));
			actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.Collect))
					.setTag(5)
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTabListener(new MyTabListener()));
			actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.Uploading))
					.setTag(6)
//					.setIcon(getResources().getDrawable(R.drawable.ic_launcher))
					.setTabListener(new MyTabListener()));
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch(item.getItemId())
		{
		case android.R.id.home:
			Intent intent=new Intent(this,AfterLandingActivity.class);
			intent.putExtra("isStartTwoClose", true);
			startActivity(intent);
			finish();
			overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
			break;
		}
		return true;
	}
	public class MyTabListener implements ActionBar.TabListener{

		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			// TODO Auto-generated method stub
			switch(Integer.parseInt(tab.getTag().toString()))
			{
			case 0:
				//配对
				AfterLandingMessageItem00 afterLandingMessageItem00=new AfterLandingMessageItem00();
				Bundle bun=new Bundle();
				bun.putString("uid", uid);
				afterLandingMessageItem00.setArguments(bun);
				ft.replace(R.id.notice_layout, afterLandingMessageItem00, "AfterLandingMessageItem00()");
				break;
			case 1:
				//创立
				AfterLandingMessageItem01 afterLandingMessageItem01=new AfterLandingMessageItem01();
				Bundle bun1=new Bundle();
				bun1.putString("uid", uid);
				afterLandingMessageItem01.setArguments(bun1);
				ft.replace(R.id.notice_layout, afterLandingMessageItem01, "AfterLandingMessageItem01()");
				break;
			case 2:
				//赞
				AfterLandingMessageItem02 afterLandingMessageItem02=new AfterLandingMessageItem02();
				Bundle bun2=new Bundle();
				bun2.putString("uid", uid);
				afterLandingMessageItem02.setArguments(bun2);
				ft.replace(R.id.notice_layout, afterLandingMessageItem02, "AfterLandingMessageItem02()");
				break;
			case 3:
				//评论
				AfterLandingMessageItem03 afterLandingMessageItem03=new AfterLandingMessageItem03();
				Bundle bun3=new Bundle();
				bun3.putString("uid", uid);
				afterLandingMessageItem03.setArguments(bun3);
				ft.replace(R.id.notice_layout, afterLandingMessageItem03, "AfterLandingMessageItem03()");
				break;
			case 4:
				//分享
				AfterLandingMessageItem04 afterLandingMessageItem04=new AfterLandingMessageItem04();
				Bundle bun4=new Bundle();
				bun4.putString("uid", uid);
				afterLandingMessageItem04.setArguments(bun4);
				ft.replace(R.id.notice_layout, afterLandingMessageItem04, "AfterLandingMessageItem04()");
				break;
			case 5:
				//收藏
				AfterLandingMessageItem05 afterLandingMessageItem05=new AfterLandingMessageItem05();
				Bundle bun5=new Bundle();
				bun5.putString("uid", uid);
				afterLandingMessageItem05.setArguments(bun5);
				ft.replace(R.id.notice_layout, afterLandingMessageItem05, "AfterLandingMessageItem05()");
				break;
			case 6:
				//上传
				AfterLandingMessageItem06 afterLandingMessageItem06=new AfterLandingMessageItem06();
				Bundle bun6=new Bundle();
				bun6.putString("uid", uid);
				afterLandingMessageItem06.setArguments(bun6);
				ft.replace(R.id.notice_layout, afterLandingMessageItem06, "AfterLandingMessageItem06()");
				break;
			}
		}
		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
			// TODO Auto-generated method stub
			
		}
		
	}

}
